package cn.ultrarisk.scadmin.manager.web.controller.log;

import cn.ultrarisk.mybatis.extension.domain.Page;
import cn.ultrarisk.scadmin.manager.biz.monitor.dao.SlowLogDAO;
import cn.ultrarisk.scadmin.manager.biz.monitor.entity.SlowLog;
import cn.ultrarisk.scadmin.manager.web.controller.BaseController;
import cn.ultrarisk.scadmin.manager.web.dto.log.SlowLogDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * LoggerController
 *
 * @author sevendlong(lin23871@163.com)
 * @date 2014/4/17
 * @since V1.0
 */
@Controller
@RequestMapping(value = "/log/slow")
public class SlowLogController extends BaseController {
    @Autowired
    private SlowLogDAO slowLogDAO;

    @ResponseBody
    @RequestMapping(value = "", method = RequestMethod.GET)
    public ResponseEntity<Page<SlowLog>> query(SlowLogDTO dto, int pageNo, int pageSize) {
        Page<SlowLog> paged = slowLogDAO.findPage(dto.getCollectionId(), dto.getElapsedTime(), dto.getOptStartTime(), dto.getOptEndTime(),
                dto.getElapsedTimeMin(), pageNo, pageSize);
        return getOkResponseEntity(paged);
    }

    @ResponseBody
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public ResponseEntity<SlowLog> view(@PathVariable("id") Long id) {
        return getOkResponseEntity(slowLogDAO.get(id));
    }
}
